const api = require('../../../ws_micro_shop/utils/api.js');
const app = getApp();

Page({
  data: {
    content: '',
    btnName: '',
  },
  bindinput(e) {
    this.setData({
      content: e.detail.content,
    });
  },
  onLoad(options) {
    let id = options.id || '';
    let btnName; let title; let placeholder; let url; let
      data = {};
    let type = 'addFollow';
    switch (type) {
      case 'addFollow':
        btnName = '添加';
        title = '添加跟进';
        placeholder = '添加客户的最新动态';
        url = api.staff.edit_followup;
        break;
    }
    wx.setNavigationBarTitle({
      title,
    });
    this.setData({
      btnName,
      placeholder,
      url,
      data,
      id,
    });
  },
  confirm() {
    let { content, url, data, id } = this.data;
    data.content = content;
    data.customer_id = id;
    app.ws_micro_shoprequest({
      url,
      data,
      method: 'post',
      success: (res) => {
        if (res.code === 0) {
          wx.showToast({
            title: '添加成功',
            icon: 'success',
            mask: true,
            duration: 1500,
          });
          setTimeout(() => {
            wx.navigateBack({
              delta: 1,
            });
          }, 1500);
        } else {
          wx.showToast({
            title: res.msg,
            icon: 'none',
            mask: true,
            duration: 1500,
          });
        }
      },
    });
  },
});
